﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class FriendCarriage : CarriageScriptBase
{
	List<GameObject> enemies = new List<GameObject>();

	protected override void GetEnemies()
	{
		enemies.Clear ();

		foreach(GameObject enemy in GameObject.FindGameObjectsWithTag ("Enemy"))
		{
			enemies.Add(enemy);
		}

	}
	
	
	protected override bool CheckIfEnemyInRange()
	{
		GetEnemies ();

		GameObject closestEnemy = null;
		float closestDist = 1000.0f;

		foreach(GameObject enemy in enemies)
		{
			float dist = Vector3.Distance (transform.position, enemy.transform.position);
			if(dist< closestDist)
			{
				closestDist = dist;
				closestEnemy = enemy;
			}
		}

		if(closestEnemy != null)
			currentEnemy = closestEnemy.transform;
		else
			Debug.Log ("ERROR: found no enemies");

		return (closestDist<MaxAttackRange);
	}
	
}